package com.bawei.module_home.ui.merchant.profiles

import android.view.View
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.lib_common.utils.ToastUtils
import com.bawei.module_home.R
import com.bawei.module_home.databinding.ActivityProfilesDetailBinding
import com.bawei.module_home.http.HomeServiceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.PROFILES_DETAIL_PAGE)
class ProFilesDetailActivity : BaseActivity<HomeServiceViewModel, ActivityProfilesDetailBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_profiles_detail
    @Autowired(name = "profileId")
    @JvmField
    var profileId=0

    val mViewModel: HomeServiceViewModel by viewModels()

    override fun initView() {
        super.initView()
        mBinding.toobar.apply {
            more.visibility= View.GONE
            title.text="企业详情"

        }
    }

    override fun initData() {
        mViewModel.getProfilesDetail(profileId)
    }

    override fun initListener() {
        mViewModel.mProfilesDetailState.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {
                    ToastUtils.showLong(this,it.message)
                }
                Loading -> {}
                Success -> {
                    ToastUtils.showLong(this,"获取成功")
                    mBinding.merName.setText(mViewModel.profileDetailItem.value?.name)
                    mBinding.merType.setText(mViewModel.profileDetailItem.value?.industryType)
                    mBinding.merAddress.setText(mViewModel.profileDetailItem.value?.address)
                    mBinding.merAuter.setText(mViewModel.profileDetailItem.value?.legalRepresentative)
                    mBinding.merStatus.setText(mViewModel.profileDetailItem.value?.status)
                    if(mViewModel.profileDetailItem.value?.status.equals("运营中")){
                        mBinding.merStatus.background=ContextCompat.getDrawable(mBinding.root.context,R.drawable.area_status_green)
                    }else{
                        mBinding.merStatus.background=ContextCompat.getDrawable(mBinding.root.context,R.drawable.area_status_yellow)
                    }

                    mBinding.merImg.setImageResource(R.mipmap.company)

                }
            }
        }
    }
}